package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.PackageSize;
import cn.stylefeng.guns.modular.system.model.params.PackageSizeParam;
import cn.stylefeng.guns.modular.system.model.result.resultVO.packageSizeVO;
import cn.stylefeng.guns.modular.system.service.PackageSizeService;
import cn.stylefeng.guns.modular.system.service.ProductOrderService;
import cn.stylefeng.guns.modular.system.service.impl.PackageSizeServiceImpl;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;


/**
 * 产品包装尺寸表控制器
 *
 * @author 小飞
 * @Date 2019-06-27 14:35:37
 */
@Controller
@RequestMapping("/packageSize")
public class PackageSizeController extends BaseController {

    private String PREFIX = "/packageSize";

    @Autowired
    private PackageSizeService packageSizeService;
    @Autowired
    private ProductOrderService productOrderService;

    /**
     * 跳转到主页面
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/packageSize.html";
    }

    /**
     * 新增页面
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/packageSize_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/packageSize_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(PackageSizeParam packageSizeParam) {

        PackageSize packageSize = new PackageSizeServiceImpl().getEntity(packageSizeParam);

        BigDecimal volume = packageSize.getLength().multiply(packageSize.getTall()).multiply(packageSize.getWide()).divide(new BigDecimal(Math.pow(100,3)));
        packageSize.setVolume(volume.setScale(4,BigDecimal.ROUND_HALF_UP));
        packageSizeService.save(packageSize);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(PackageSizeParam packageSizeParam) {
        this.packageSizeService.update(packageSizeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(PackageSizeParam packageSizeParam) {
        this.packageSizeService.delete(packageSizeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(PackageSizeParam packageSizeParam) {
        PackageSize detail = this.packageSizeService.getById(packageSizeParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 小飞
     * @Date 2019-06-27
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(PackageSizeParam packageSizeParam) {

        return this.packageSizeService.findPageBySpec(packageSizeParam);
    }

}


